package com.gxc.randomArray;

import java.util.Random;

/**
 * Created by ASD on 2022/12/22.
 */
public class generateRandomArray {

    public static int[] generateArray(int maxSize, int maxValue) {
        int[] arr = new int[(int) (maxSize * Math.random())];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int) ((maxValue+1) * Math.random()) - (int)(maxValue * Math.random());
        }
        return arr;
    }

    public static int[] generateArray2(int maxSize, int maxValue) {
        int[] arr = new int[(int) (maxSize * Math.random())];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int) ((maxValue+1) * Math.random());
        }
        return arr;
    }

    public static void main(String[] args) {
        sout(generateArray(20, 30));
    }

    public static void sout(int[] arr) {
        System.out.println("");
        for (int i : arr) {
            System.out.print(i);
            System.out.print("    ");
        }
    }

    //交换值
    public static void swap(int[] arr, int i, int j )  {
        if (arr[i] == arr[j]) return;
        arr[i] = arr[i] ^ arr[j];
        arr[j] = arr[i] ^ arr[j];
        arr[i] = arr[i] ^ arr[j];
    }
}
